﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace WebApplication1
{
    /// <summary>
    /// Descripción breve de MyWebService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // Para permitir que se llame a este servicio Web desde un script, usando ASP.NET AJAX, quite la marca de comentario de la línea siguiente.
    [System.Web.Script.Services.ScriptService]
    public class MyWebService : System.Web.Services.WebService
    {
        [WebMethod]
        public string SayHello(string firstName, string lastName)
        {
            return "Hello " + firstName + " " + lastName;
        }

        [WebMethod]
        public string SayHelloJson(string firstName, string lastName)
        {
            var data = new { Greeting = "Hello", Name = firstName + " " + lastName };

            // We are using an anonymous object above, but we could use a typed one too (SayHello class is defined below)
            // SayHello data = new SayHello { Greeting = "Hello", Name = firstName + " " + lastName };

            System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();

            return js.Serialize(data);
        }

        [WebMethod]
        public SayHello SayHelloObject(string firstName, string lastName)
        {
            SayHello o = new SayHello();
            o.Greeting = "Hello";
            o.Name = firstName + " " + lastName;
            System.Threading.Thread.Sleep(3000);
            return o;
        }
    }
}